/*
		* Author:	 Sander
		* Date:		 12-apr-2011
		* Name:		 Light
		* Version:	1.0
		*
		* This code is property of Sander blahblahblah copyright blahblah.
*/


package javaraytracer.Objects;

import javaraytracer.IntersectionInfo;
import javaraytracer.Materials.*;
import javaraytracer.Ray;
import javaraytracer.Vec3;


//PENDING:add function/property description
/**
 * A light, created in the scene of the raytracer.
 * @author Sander
 */
public class Light extends Traceable
{
	public Vec3 location;
	public Vec3 col;
	public float intensity;
	public float distance;

	Sphere body;

	/**
	 * Creates a simple small light
	 */
	public Light()
	{
		location = new Vec3();
		col = new Vec3( 1, 1, 1 );
		intensity = 1;
		distance = 10;

		makeBody();
	}
	/**
	 * Creates a light on a certain position
	 * @param pos Position of the light.
	 * @param c Color of the light.
	 * @param i Intensity of the light.
	 */
	public Light(Vec3 pos, Vec3 c, float i)
	{
		location = pos;
		col = c;
		intensity = i;
		distance = 10 * i;

		makeBody();
	}
	/**
	 * Creates a light on a certain position with a distance variable
	 * @param pos Position of the light.
	 * @param c Color of the light.
	 * @param i Intensity of the light.
	 * @param d Distance of the light.
	 */
	public Light(Vec3 pos, Vec3 c, float i, float d)
	{
		location = pos;
		col = c;
		intensity = i;
		distance = d * i;

		makeBody();
	}

	private void makeBody()
	{
		material = new Material(col, col, 0f, 1 + intensity, false, false);
		body = new Sphere( new Vec3(location), 0.1f, material);
	}

	public IntersectionInfo intersect( Ray r )
	{
		return body.intersect(r);
	}

	/**
	 * Checks if a ray hits the light.
	 * @param r Ray that would hit the light.
	 * @return true if hit, false if not hit.
	 */
	public boolean hit ( Ray r )
	{
		return body.hit(r);
	}

	public Material getMaterial()
	{
		return body.getMaterial();
	}

	public Material getMaterial(IntersectionInfo info)
	{
		return body.getMaterial(info);
	}

}
